import React from 'react';
import { ActivityIndicator, StatusBar, View, StyleSheet } from 'react-native';
import GlobalStyles from '../style/GlobalStyles';
import NavigationUtil from '../navigation/NavigationUtil';

export default class LoginLoadingScreen extends React.Component {
    constructor(props) {
        super(props);
        NavigationUtil.navigation = this.props.navigation;
        this._bootstrapAsync();
    }

    _bootstrapAsync = async () => {
        global.storage.load({ key: 'userInfo' }).then(ret => {
            NavigationUtil.goPage(ret.token ? 'App' : 'Auth');
        }).catch(() => {
            NavigationUtil.goPage('Auth');
        });
    };

    render() {
        return (
            <View style={styles.container}>
                <ActivityIndicator/>
                <StatusBar barStyle="default"/>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        width: GlobalStyles.DEVICE_WIDTH,
        height: GlobalStyles.DEVICE_HEIGHT
    }
});
